﻿#include "dialogmodifycase.h"
#include "ui_dialogmodifycase.h"

DialogModifyCase::DialogModifyCase(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::DialogModifyCase)
{
    ui->setupUi(this);
}

DialogModifyCase::DialogModifyCase(EKEChildCase &childCase, QWidget *parent):
    QDialog(parent),
    ui(new Ui::DialogModifyCase)
{
    ui->setupUi(this);
    _childCase=childCase;
    showEditInfo();
}

DialogModifyCase::~DialogModifyCase()
{
    delete ui;
}

EKEChildCase DialogModifyCase::GetChildCase()
{
    return _childCase;
}

void DialogModifyCase::showEditInfo()
{
    ui->lineEdit_caseDiscription->setText(_childCase._childCaseName);
    ui->lineEdit_caseNumber->setText(_childCase._childCaseNumber);
    ui->lineEdit_preCondition->setText(_childCase._precondition.join(";"));

    QStringList inputList;
    for (int i = 0; i < _childCase._inputs.count(); ++i)
    {
        inputList<<_childCase._inputs[i].first+"="+_childCase._inputs[i].second;
    }

    ui->lineEdit_input->setText(inputList.join(";"));
    QStringList outputList;
    for (int i = 0; i < _childCase._output.count(); ++i)
    {
        outputList<<_childCase._output[i].first+"="+_childCase._output[i].second;
    }
    ui->lineEdit_output->setText(outputList.join(";"));

}
void DialogModifyCase::setEKEchildCase()
{
    _childCase._childCaseName = ui->lineEdit_caseDiscription->text();
    _childCase._childCaseNumber = ui->lineEdit_caseNumber->text();
    _childCase._precondition = ui->lineEdit_preCondition->text().split(";");
    QList<QPair<QString,QString>> input;
    auto inputKeyValue = ui->lineEdit_input->text().split(";");
    for (int i = 0; i < inputKeyValue.count(); ++i)
    {
       auto keyvalueList=  inputKeyValue[i].split("=");
        input.push_back(QPair<QString,QString>(keyvalueList[0],keyvalueList[1]));
    }

    QList<QPair<QString,QString>> output;
    auto outputKeyValue = ui->lineEdit_output->text().split(";");
    for (int i = 0; i < outputKeyValue.count(); ++i)
    {
        auto keyvalueList=  outputKeyValue[i].split("=");
        output.push_back(QPair<QString,QString>(keyvalueList[0],keyvalueList[1]));
    }
    _childCase._inputs  =input;
    _childCase._output  =output;

}

void DialogModifyCase::on_btn_ensure_clicked()
{
    setEKEchildCase();
    accept();
}


void DialogModifyCase::on_btn_cancel_clicked()
{
    reject();
}

